local easyHurtSkill = fk.CreateSkill {
  name = "easyHurtSkill",
  tags = { Skill.Compulsory, },
}


easyHurtSkill:addEffect(fk.DamageFinished, {
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(easyHurtSkill.name) and target == player and data.card and not player.dead and
    player:getMark("@up_easyhurt") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tatal_damaged = player:getMark("tatal_damaged")
    local per = 4
    local per_damage = data.damage / per
    local mod_damage = data.damage % per
    per_damage = per_damage > 0 and math.floor(per_damage) or 0
    mod_damage = (mod_damage + tatal_damaged) % per == 0 and 1 or 0
    room:setPlayerMark(player, "tatal_damaged", tatal_damaged + data.damage)
    if per_damage + mod_damage > 0 then
      room:damage({
        to = player,
        damage = per_damage + mod_damage,
        damageType = fk.NormalDamage,
        skillName = easyHurtSkill.name
      })
    end
  end,
})

easyHurtSkill:addEffect(fk.TurnEnd, {
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(easyHurtSkill.name) and target == player and player:getMark("@up_easyhurt") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player, "@up_easyhurt", 1)
    local mark = player:getMark("@up_easyhurt")
    if mark <= 0 then
      room:handleAddLoseSkills(player, "-easyHurtSkill", nil, false)
    end
  end,
})

easyHurtSkill:addEffect(fk.EventLoseSkill, {
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return player == target and data == self and
    (player:getMark("tatal_damaged") > 0 or player:getMark("@up_easyhurt") > 0)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "tatal_damaged", 0)
    room:setPlayerMark(player, "@up_easyhurt", 0)
  end,
})


return easyHurtSkill
